<template>
	<view class="p30 ">
		<view class="bg-fff radius20 p20 flex">
			<view class="color-zs flex1">
				<view class="fw-w  fs30">+￥{{data.master_money}}</view>
				<!-- <view class="fs26" v-if="data.tip_price*1">小费+￥{{data.tip_price}}</view> -->
			</view>
		</view>

		<view class="bg-fff radius20 p20 mt20" v-if="data.status==5&&data.comment">
			<view class="tit-ac fw-w flex mb20" style="margin-left: -20rpx;">
				<view class="">评价内容</view>
				<view class="flex1"></view>
			</view>
			<comment :item="data.comment" reply />
		</view>

		<view class="bg-fff radius20 p20 mt20" v-if="data.status==3||data.photos_path">
			<view class="tit-ac fw-w flex" style="margin-left: -20rpx;">
				<view class="">完工照片</view>
				<view class="flex1"></view>
				<u-button size="mini" type="warning" v-if="data.status==3" @click="upImgShow=true">上传照片</u-button>
			</view>
			<view class="h20"></view>
			<z-imgs :paths="data.photos_path" look margin="20" radius="10" />
			<u-popup v-model="upImgShow" mode="bottom" borderRadius="20" :maskCloseAble="true" closeable zIndex="999">
				<view class="p40 ">
					<view class="tc fw-w fs32">上传照片</view>
					<view class="mt40 mb40" style="min-height: 420rpx;">
						<z-imgs up max="6" ref="photos" :ids="data.photos" :paths="data.photos_path" />
					</view>
					<view class="">
						<u-button type="warning" ripple @click="uploadPhotos">确认</u-button>
					</view>
				</view>
			</u-popup>
		</view>
		<block v-for="(item9,index9) in infoList" :key="index9">
			<view class="bg-fff radius20 p20 mt20">
				<view class="tit-ac fw-w " style="margin-left: -20rpx;">{{item9.title}}</view>
				<block v-for="(item,index) in item9.list" :key="index">
					<view class="" v-if="item.type=='arr'">
						<block v-for="(item2,index2) in item.value" :key="index2">
							<view class="color-666 pt12">{{item.name+''+(index2+1)}}</view>
							<view class="flex row-between flex-wrap pt12 pb12 ml10" v-for="(item3,index3) in item.list"
								:key="index3">
								<view class="color-666" v-if="item3.name">{{item3.name}}</view>
								<view class="" :class="item3.class">{{item2[item3.fidle]}}</view>
							</view>
						</block>
					</view>
					<view class="flex row-between col-top pt12 pb12 ov-h" v-else @click="itemClick(item)">
						<view class="color-666 nowrap mr20 flex1" :class="item.nameClass" v-if="item.name">{{item.name}}
						</view>
						<block v-if="item.type=='img'">
							<view class="ml10" v-for="(item2,index2) in $tool.paths(item.value)" :key="index2"
								@click="lookImg(item.value,index2)">
								<image :src="item2" class="w200 h200 radius10" mode="aspectFit"></image>
							</view>
						</block>
						<view class="" :class="item.class" v-else style="word-break: break-all;">{{item.value}}</view>
						<view class="" v-if="item.isNav">
							<u-icon name="map" :color="$zs" />
						</view>
						<view class="" v-if="item.phone" style="transform: rotateY(180deg);">
							<u-icon name="phone" :color="$zs" />
						</view>
					</view>
				</block>
			</view>
		</block>
		<view class="pt20 color-999 flex row-center" v-if="[2].includes(data.status)">
			<view class=""
				@click="$jump('/pages/order/cancel',{...$params,money:data.pay_price,tip_price:data.tip_price})">取消订单
			</view>
		</view>
		<view class="pt20">特殊说明：</view>
		<view class="">
			<u-parse :html="data.order_tips" :domain="$baseUrl" />
		</view>

		<view class="h180"></view>
		<view class="pf bottom0 left0 bg-fff  w-max">
			<view class="tc pt20 fs24 color-999" v-if="data.close_countdown">
				<text class="">若在</text>
				<u-count-down :timestamp="data.close_countdown||0" font-size="26" separator-size="26"
					bg-color="transparent" :show-seconds="true" :color="$fs" :separator-color="$fs" />
				<text class="">内无人接单，超时订单将自动取消</text>
			</view>
			<view class="tc pt20 fs24 color-999" v-else-if="data.pay_countdown">
				<text class="">请在</text>
				<u-count-down :timestamp="data.pay_countdown||0" font-size="26" separator-size="26"
					bg-color="transparent" :show-seconds="true" :color="$fs" :separator-color="$fs" />
				<text class="">内支付，超时订单将自动取消</text>
			</view>
			<view class="tc pt20 fs24 color-999" v-else-if="data.trade_countdown&&$config.is_show_agency == 1">
				<text class="">转单截止</text>
				<u-count-down :timestamp="data.trade_countdown||0" font-size="26" separator-size="26"
					bg-color="transparent" :show-seconds="true" :color="$fs" :separator-color="$fs" />
			</view>
			<view class=" flex">
				<view class="flex1 p20 " v-if="data.status===0">
					<u-button type="warning" ripple
						@click="$jump('/pages/index/demo/pay',{order_sn:data.order_sn})">立即付款</u-button>
				</view>
				<view class="flex1 p20 " v-if="data.is_show_trade==1&&$config.is_show_agency == 1">
					<u-button type="warning" ripple @click="trade">转单</u-button>
				</view>
				<view class="flex1 p20 " v-if="data.status==1">
					<u-button type="warning" ripple @click="receiveOrde">立即接单</u-button>
				</view>
				<view class="flex1 p20 " v-if="data.status==2">
					<u-button type="warning" ripple @click="beginOrder">开始服务</u-button>
				</view>
				<view class="flex1 p20 " v-if="data.status==3">
					<u-button type="warning" ripple
						@click="data.photos?$refs.modal.open():$msg('请上传完工照片')">完成订单</u-button>
				</view>
			</view>
		</view>
		<modal ref="modal" title="完成订单" type="number" placeholder="请输入订单确认码"
			@confirm="$refs.modal.cancel(),finishOrder($event)"></modal>

		<!-- <auto-select api="/master/agency/joinList" ref="joinList" labelName="name" valueName="id" childName="master"></auto-select> -->
		<u-popup v-model="zhuanShow" mode="bottom" borderRadius="20" closeable z-index="999">
			<view class="p40">
				<view class="fs32 fw-w tc pb30">转单</view>
				<scroll-view scroll-y class="x" style="max-height: 800rpx;">
					<view class="p20 radius20  bg-f5f mb20" v-for="(item,index) in joinList" :key="index">
						<view class="flex">
							<u-avatar :src="item.avatar" size="80"></u-avatar>
							<view class="flex1 ml20">{{item.name}}</view>
							<view class="ml10" v-if="item.master&&item.master.length">
								<u-button size="mini" type="warning"
									@click="item.show=!item.show">{{item.show?'收起':'展开'}}</u-button>
							</view>
							<view class="ml10">
								<!-- <u-button size="mini" type="warning" @click="tradeOrder('agency_id',item)">选择</u-button> -->
								<u-button size="mini" type="warning" @click="tradeOrder(item)">选择</u-button>
							</view>
						</view>
						<view class="" v-if="item.show">
							<view class="p20 pr0 flex border-b" v-for="(item2,index2) in item.master" :key="index2">
								<u-avatar :src="item2.avatar" size="60"></u-avatar>
								<view class="flex1 ml20">{{item2.name}}</view>
								<view class="ml10">
									<!-- 	<u-button size="mini" type="warning"
										@click="tradeOrder('master_id',item2)">选择</u-button> -->
									<u-button size="mini" type="warning" @click="tradeOrder(item,item2)">选择</u-button>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				zhuanShow: false,
				is_trade_show: false,
				master_list: [], //团队列表

				upImgShow: false,
				data: '',
				// photos:''
				joinList: ''
			};
		},
		onLoad() {

		},
		onShow() {
			this.getData()
		},
		methods: {
			itemClick(item) {
				let data = this.data || ''
				console.log(item);
				if (item.isNav) {
					uni.openLocation({
						latitude: data.latitude * 1,
						longitude: data.longitude * 1,
						name: data.hospital,
					})
				} else if (item.phone) {
					this.$tool.phone(item.value)
				}
			},
			async trade() {
				let list = [{
						name: '大厅',
						show: !!this.data.agency_id,
						fn: this.tradeOrder2
					},
					{
						name: '团队',
						fn: () => {
							this.get_joinList()
							// uni.$once('trade', this.tradeOrder)
							// this.$jump('/pages/my/team/team', {
							// 	set: 'trade'
							// })
						},
						show: true
					},
				]
				list = list.filter(e => e.show)
				if (list.length == 1) return list[0].fn()
				await this.$tool.showActionSheet(list)

			},

			get_joinList(item) { //接单
				if (this.joinList.length) return this.zhuanShow = true
				this.$request('/master/agency/joinList').then(res => {
					this.joinList = res.data.map(e => {
						e.show = false
						return e
					})
					this.zhuanShow = true
				})
			},
			async tradeOrder2(item) { //接单
				await this.$showModal('提示', '确认转到到大厅吗')
				let params = {
					...this.$params,
				}
				this.$request('/master/order/tradeOrder', params).then(res => {
					this.$msg(res.msg)
					this.$navBack(1, 1000)
				})
			},
			// async tradeOrder(type, item) { //接单
			// 	await this.$showModal('提示', '确认转到到' + item.name)
			// 	let params = {
			// 		...this.$params,
			// 	}
			// 	params[type] = item.id
			// 	this.$request('/master/order/tradeOrder', params).then(res => {
			// 		this.zhuanShow = false
			// 		this.$msg(res.msg)
			// 		this.$navBack(1, 1000)
			// 	})
			// },
			async tradeOrder(item, item2 = '') { //接单
				await this.$showModal('提示', '确认转到到' + (item2.name || item.name))
				let params = {
					...this.$params,
					agency_id: item.id,
					master_id: item2.id,
				}
				this.$request('/master/order/tradeOrder', params).then(res => {
					this.zhuanShow = false
					this.$msg(res.msg)
					this.$navBack(1, 1000)
				})
			},
			async uploadPhotos() { //上传完结照片
				this.$request('/master/order/uploadPhotos', {
					...this.$params,
					photos: this.$refs.photos.success()
				}).then(res => {
					this.$msg(res.msg)
					this.getData()
					this.upImgShow = false
				})
			},
			async finishOrder(verify_code) { //完成服务（核销）
				this.$request('/master/order/finishOrder', {
					...this.$params,
					verify_code
				}).then(res => {
					this.$msg(res.msg)
					this.getData()
				})
			},
			async receiveOrde() { //接单
				await this.$showModal('接单')
				this.$request('/master/order/receiveOrder', this.$params).then(res => {
					this.$msg(res.msg)
					this.getData()
				})
			},
			async beginOrder() { //接单
				await this.$showModal('开始服务')
				this.$request('/master/order/beginOrder', this.$params).then(res => {
					this.$msg(res.msg)
					this.getData()
				})
			},
			getData() { //订单数据
				this.$request('/master/order/orderInfo', this.$params).then(res => {
					this.data = res.data
				})
			},
			lookImg(value, index) { //查看图片
				this.$tool.lookImg(this.$tool.paths(value), index)
			},
			getPatient() { //患者
				let data = this.data?.patient || ''
				if (!data) return ''
				let aa = ''
				if (data.name) aa = aa + data.name
				if (data.relation) aa = aa + ' ' + data.relation
				if (data.sex) aa = aa + ' ' + this.$list('sex', data.sex)
				if (data.age) aa = aa + ' ' + data.age
				return aa || ''
			},
			getAddress() { //收货地址
				let data = this.data?.address || ''
				if (!data) return ''
				let aa = ''
				if (data.name) aa = aa + data.name
				if (data.mobile) aa = aa + ' ' + data.mobile
				if (data.address) aa = aa + ' ' + data.address
				return aa || ''
			},
			get_transfer() { //接送地址
				let data = this.data?.transfer || ''
				if (!data) return ''
				let aa = ''
				if (data.name) aa = aa + data.name
				if (data.mobile) aa = aa + ' ' + data.mobile
				if (data.address) aa = aa + ' ' + data.address
				return aa || ''
			},
		},
		computed: {

			infoList() {
				let data = this.data || ''
				let arr = [{
					title: '预约信息',
					list: [{
							name: '就诊人',
							// `${patient.name} ${patient.relation} ${this.$list('sex', patient.sex)} ${patient.age}`
							value: this.getPatient()
						},
						{
							name: '期望服务时间',
							value: data.expect_time
						},
						{
							name: '期望价格',
							value: data.expect_price
						},
						{
							name: '医院',
							value: data.hospital,
							isNav: true
						},
						{
							name: '科室',
							value: data.department,
							class: 'color-zs'
						},
						{
							name: '日期',
							value: data.date,
						},
						{
							name: '开始时间',
							value: data.start_time,
						},
						{
							name: '结束时间',
							value: data.end_time,
						},
						{
							name: '开始日期',
							value: data.start_date,
						},
						{
							name: '结束日期',
							value: data.end_date,
						},
						{
							name: '联系电话',
							value: data.status >= 2 ? data.mobile : '',
							phone: true
						},
						{
							name: '挂号类型',
							value: data.register_type === 1 ? '专家号' : data.register_type === 0 ? '普通号' : '', //
						},
						{
							name: '药品',
							value: data.drugs, //
							type: 'arr',
							list: [{
									name: '企业',
									fidle: 'drugs_factory'
								},
								{
									name: '药品名称',
									fidle: 'drugs_name'
								}, {
									name: '数量',
									fidle: 'drugs_num'
								}, {
									name: '规格',
									fidle: 'drugs_specs'
								}
							]
						},
						{
							name: '预估费用',
							value: data.estimate_price * 1 && data.estimate_price,
						},
						{
							name: '保价服务费',
							value: data.insured_price * 1 && data.insured_price,
						},
						{
							name: '医生',
							value: data.doctor,
						},
						{
							name: '陪诊师性别',
							value: this.$list('sex', data.master_sex),
						},
						{
							name: '报告类型',
							value: data.report_type,
						},
						{
							name: '是否保价',
							value: data.is_insured === 1 ? '是' : data.is_insured === 0 ? '否' : '',
						},
						{
							name: '是否需要发票',
							value: data.is_invoice === 1 ? '是' : data.is_invoice === 0 ? '否' : '',
						},
						{
							name: '是否允许转单',
							value: data.is_trade === 1 ? '是' : data.is_trade === 0 ? '否' : '',
						},
						{
							name: '登记号',
							value: data.register_no,
						},
						{
							name: '就诊二维码',
							value: data.qr_code,
							type: 'img'
						},
						{
							name: '报告单条形码',
							value: data.bar_code,
							type: 'img'
						},
						{
							name: '处方照片',
							value: data.prescription,
							type: 'img'
						},
						{
							name: '床号',
							value: data.bed_num,
						},
						{
							name: '自理能力',
							value: data.ability,
						},
						{
							name: '服务天数',
							value: data.days,
						},
						{
							name: '诊断结果',
							value: data.results,
						},
						{
							name: '接送服务',
							value: data.is_transfer === 1 ? '是' : data.is_transfer === 0 ? '否' : '',
						},
						{
							name: '接送地址',
							value: this.get_transfer(),
						},
						{
							name: '收件地址',
							value: this.getAddress(),
						},
						{
							name: '服务需求',
							value: data.remarks,
						},
						{
							name: '',
							value: data.images,
							type: 'img'
						},
					]
				}, {
					title: '订单信息',
					list: [{
							name: '订单状态',
							value: data.status_text,
							class: 'color-fs'
						},
						{
							name: '订单编号',
							value: data.order_sn,
						},
						{
							name: '服务类型',
							value: data.service_name,
							class: 'color-zs'
						},
						{
							name: '订单金额',
							value: data.service_price,
						},
						{
							name: '保价服务费',
							value: data.insured_price * 1 && data.insured_price,
						},
						{
							name: '优惠金额',
							value: data.coupon_price * 1 && data.coupon_price,
							class: "color-fs"
						},
						{
							name: '小费金额',
							value: data.tip_price * 1 && data.tip_price,
						},
						{
							name: '实付金额',
							value: data.pay_price * 1 && data.pay_price,
							class: "color-fs"
						},
						{
							name: '下单时间',
							value: data.add_time,
						},
						{
							name: '支付时间',
							value: data.pay_time,
						},
						{
							name: '雇佣时间',
							value: data.hire_time,
						},
						{
							name: '签到时间',
							value: data.signin_time,
						},
						{
							name: '接单时间',
							value: data.receive_time,
						},
						{
							name: '服务开始时间',
							value: data.begin_time,
						},
						{
							name: '完成服务时间',
							value: data.finish_time,
						},
						{
							name: '取消时间',
							value: data.cancel_time,
						},
						{
							name: '核销时间',
							value: data.verify_time,
						},
						{
							name: '验收时间',
							value: data.check_time,
						},
						{
							name: '服务内容',
							value: data.receive?.service_content || '',
						},
						{
							name: '服务照片',
							value: data.receive?.pics || '',
							type: 'img',
							nameClass: 'w-max pb20'
						},
						{
							name: '药品照片',
							value: data.receive?.drugs_pic || '',
							type: 'img',
							nameClass: 'w-max pb20'
						},
						{
							name: '发票照片',
							value: data.receive?.bill_pic || '',
							type: 'img',
							nameClass: 'w-max pb20'
						},
						{
							name: '快递单号照片',
							value: data.receive?.express_pic || '',
							type: 'img',
							nameClass: 'w-max pb20'
						},
					]
				}]
				arr = arr.filter(item => {
					item.list = item.list.filter(item2 => item2.value)
					return item.list.length
				})
				return arr
			}
		},
	}
</script>

<style lang="scss">

</style>